/*
 * IEDDetectionTest.cpp
 *
 *  Created on: Jun 23, 2011
 *      Author: jrodrig9
 */

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<time.h>
#include "../SUDSC2Interface.h"

using namespace std;

void wait(int seconds);

int main(int argc, char* argv[])
{
	SUDSC2Interface SUDS;
	char buffer[500];
	ifstream inFile;
	ofstream outFile;
	int leftsensor, rightsensor;
	bool detection[2] = {false,false};

	inFile.open("instructionSet.txt", ifstream::in);
	if(inFile.fail())
	{
		cout << "Can't open dataSet file\n";
		exit(1);
	}

	outFile.open("dataSet.txt");
	if(outFile.fail())
	{
		cout << "Can't open dataSet file\n";
		exit(1);
	}

	for(int i=0; i<12; i++){

		SUDS.update();
		leftsensor = SUDS.pollLeftSensor();
		rightsensor = SUDS.pollRightSensor();

		detection = SUDS.checkDetections();

		int a = sprintf(buffer,"Left Sensor State: %d, Right Sensor State: %d >> ",leftsensor,rightsensor);
		outFile << buffer;

		if(detection[0] = true){
			if(dection[1] = true){
				outFile << "Detection on both Sensors!!!";
			}
			else{
				outFile << "Detection on Left Sensor!!!";
			}
		}
		else{
			if(detection[1] = true){
				outFile << "Detection on Right Sensor!!!";
			}
		}

		wait(4);
	}

	inFile.close();
	outFile.close();

	cout << "Edge Detection Test Complete" << endl;

	return 0;
}

void wait ( int seconds )
{
  clock_t endwait;
  endwait = clock () + seconds * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
}
